//
//  addEmpolyeePopView.swift
//  DSHCMerchant
//
//  Created by 罗德良 on 2018/4/15.
//  Copyright © 2018年 袋鼠好车. All rights reserved.
//

import UIKit
import IQKeyboardManagerSwift
class addEmpolyeePopView: UIView {

    typealias sureOrcancleBlock = (_ boolValue:Bool) -> Void
    
    
    @IBOutlet var titleLabel: UILabel!
    
    @IBOutlet var phoneTF: UITextField!
    
    @IBOutlet var nameTF: UITextField!
    
    @IBOutlet var ageTF: UITextField!
    
    
    @IBOutlet var workTimeTF: UITextField!
    
    
    @IBOutlet var goodAtAreaTF: UITextField!
    
    @IBOutlet var sexBtn: UIButton!
    @IBOutlet var workTypeBtn: UIButton!
    
    @IBOutlet var workRoleBtn: UIButton!
    
    @IBOutlet var storeBtn: UIButton!
    
    @IBOutlet var cancleBtn: UIButton!
    
    @IBOutlet var saveBtn: UIButton!
    
    var role_id = "" //固定id  1 老板  2 店长 3 店员
    var work_id = ""
    var store_id = ""
    var sex_id = "" //固定 1 男  2女
    
    

    var tapSureOrcancle:sureOrcancleBlock?
    
    func callBackBlock(_ block: @escaping sureOrcancleBlock) {
        
        tapSureOrcancle = block
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.frame = CGRect(x:0, y:0, width:ScaleWidth(300),height:ScaleHeight(480));
        self.center = CGPoint(x: kScreenWidth/2, y: kScreenHeight/2)
        self.roundCorner(radius: 5)
    }
    
    class func getAddempolyeePopView() -> addEmpolyeePopView {
        return UIView.creatFromNIB(By: "addEmpolyeePopView") as! addEmpolyeePopView
    }
    
    
    @IBAction func sexBtnPress(_ sender: UIButton) {
        self.endEditing(true)
        BRStringPickerView.showStringPicker(withTitle: "员工性别", dataSource: ["男","女"], defaultSelValue: "男", isAutoSelect: true) { (str,index) in
            self.sexBtn.setTitle(str as? String, for: .normal)
            self.sex_id = String(index + 1)
        }
    }
    
    @IBAction func woreTypeBtnPress(_ sender: UIButton) {
        self.endEditing(true)
        var Ids = [String]()
        var Types = [String]()
        var typeArray:[EmployeeTypeModel]?
        typeArray = (UserModel.shareUser.data?.employeeTypes)!
        for (employeeType) in typeArray! {
            
            Types.append(employeeType.name)
            Ids.append(employeeType.wid)
        }
        
        BRStringPickerView.showStringPicker(withTitle: "员工职位", dataSource: Types, defaultSelValue: Types[0], isAutoSelect: true) { (str,index) in
            self.workTypeBtn.setTitle(str as? String, for: .normal)
            self.work_id = Ids[index]
        }
    }
    

    @IBAction func workRoleBtnPress(_ sender: UIButton) {
        self.endEditing(true)
        BRStringPickerView.showStringPicker(withTitle: "员工角色", dataSource: ["老板","店长","店员"], defaultSelValue: "老板", isAutoSelect: true) { (str,index) in
            self.workRoleBtn.setTitle(str as? String, for: .normal)
            self.role_id = String(index + 1)
        }
        
    }
    
    
    @IBAction func storeBtnPress(_ sender: UIButton) {
        self.endEditing(true)
        var Ids = [String]()
        var Stores = [String]()
        var storeArray:[EmployeeStoreModel]?
        storeArray = (UserModel.shareUser.data?.employeeStores)!
        for (employeeStore) in storeArray! {
            
            Stores.append(employeeStore.name)
            Ids.append(employeeStore.id)
        }
        
        BRStringPickerView.showStringPicker(withTitle: "店铺列表", dataSource: Stores, defaultSelValue: Stores[0], isAutoSelect: true) { (str,index) in
            self.storeBtn.setTitle(str as? String, for: .normal)
            self.store_id = Ids[index]
        }
    }
    
    
    @IBAction func saveBtnPress(_ sender: UIButton) {
        
        if (self.phoneTF.text == "") || (self.nameTF.text == "") || (self.ageTF.text == "") || (self.workTimeTF.text == "") || (self.goodAtAreaTF.text == "") || (sex_id == "") || (work_id == "") || (role_id == "") || (store_id == ""){
            MBProgressHUD.alertShow(in: self, message: "请填写完整再提交", hidenAfter: 0.8, mode: MBProgressHUDMode.text)
            return
        }
        
        if tapSureOrcancle != nil {
            self.tapSureOrcancle!(true)
        }
    }
    
    @IBAction func cancleBtnPress(_ sender: UIButton) {
        if tapSureOrcancle != nil {
            tapSureOrcancle!(false)
        }
    }
    
}

